package com.poc.log;
import java.io.FileWriter;
import java.io.IOException;


public class Log extends FileWriter {

	private StringBuilder stringBuilder;
	private static final Integer LOG_DUMP_SIZE = 100000;
	
	
	public Log(String fileName) throws IOException {
		super(fileName);
		this.stringBuilder = new StringBuilder();
	}

	public void append(String csq) throws IOException {
		this.stringBuilder.append(csq);

		if(this.stringBuilder.length() > Log.LOG_DUMP_SIZE) {
			super.append(this.stringBuilder);
			super.flush();
			this.stringBuilder.delete(0, this.stringBuilder.length());
			this.stringBuilder = new StringBuilder();
			
		}
		
	}
	
	@Override
	public void close() throws IOException {
		this.append(this.stringBuilder);
		super.flush();
		super.close();
	}
	
}
